package com.hbue.water.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hbue.water.entity.Worker;
import com.hbue.water.mapper.WorkerMapper;
import com.hbue.water.service.WorkerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yushu
 * @date 2021/12/24
 * @apiNate
 */
@Service
public class WorkerServiceImpl extends ServiceImpl<WorkerMapper, Worker> implements WorkerService {

    @Autowired
    private WorkerMapper workerMapper;

    @Override
    public PageInfo<Worker> listWorker(int currentPageNum, int pageSize) {
        PageHelper.startPage(currentPageNum,pageSize);
        List<Worker> workerList = workerMapper.selectList(null);
        return new PageInfo<>(workerList);
    }

    @Override
    public int adjustSalary(Worker worker) {
        QueryWrapper<Worker> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("wid", worker.getWid());
        return workerMapper.update(worker, queryWrapper);
    }

    @Override
    public PageInfo<Worker> searchCustomer(int currentPageNum, int pageSize, String searchCondition) {
        PageHelper.startPage(currentPageNum, pageSize);
        QueryWrapper<Worker> qw = new QueryWrapper<>();
        if (StrUtil.isNotEmpty(searchCondition)) {
            qw.like("worker_name", searchCondition);
        }
        List<Worker> workerList = workerMapper.selectList(qw);
        return new PageInfo<>(workerList);
    }
}
